import { Command, AudioWaveform, GalleryVerticalEnd } from 'lucide-vue-next';
import { defineStore } from 'pinia';
import { ref, computed } from 'vue';
import type { Component } from 'vue';

export interface AppInfo {
  name: string;
  logo: Component;
  description: string;
  key: string;
  disabled: boolean;
}

export const useAppStore = defineStore('app', () => {
  // 状态
  const currentAppKey = ref<string>('knowledge-management');
  const apps: AppInfo[] = [
    {
      name: '知识管理',
      logo: GalleryVerticalEnd,
      description: '知识管理信息系统',
      key: 'knowledge-management',
      disabled: false,
    },
    {
      name: 'AI问答',
      logo: AudioWaveform,
      description: 'AI问答信息系统',
      key: 'ai-question-answer',
      disabled: true,
    },
    {
      name: '系统管理',
      logo: Command,
      description: '后台信息管理',
      key: 'system-management',
      disabled: false,
    },
  ];

  const currentApp = computed(() => apps.find(app => app.key === currentAppKey.value));

  // 方法
  const setAppKey = (key: string) => {
    currentAppKey.value = key;
  };

  return {
    // 状态
    currentAppKey,
    apps,

    // 计算属性
    currentApp,

    // 方法
    setAppKey,
  };
}, {
  // 持久化配置
  persist: {
    key: 'app-store',
    storage: sessionStorage,
    paths: ['currentAppKey'],
  } as any,
});
